package com.fmsz.xmly.adapters.classify;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

/**
 * Created by Administrator on 2016/12/3.
 */

public class FindClassifyPagerAdapter extends PagerAdapter {

    private ImageView[] images;
    private String[] imageUrls;
    private Context context;

    public FindClassifyPagerAdapter(Context context, ImageView[] images, String[] imageUrls) {
        this.context = context;
        this.images = images;
        this.imageUrls = imageUrls;
    }

    @Override
    public int getCount() {
        return images.length;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(images[position]);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        images[position].setScaleType(ImageView.ScaleType.FIT_XY);
        container.addView(images[position]);
        Log.i("1620", "instantiateItem: "+position);
        Picasso.with(context).load(imageUrls[position]).into(images[position]);
        Log.i("1620", "instantiateItem: "+imageUrls[position]);
        return images[position];
    }
}
